package com.ellricky.baselib.ui.cla

import android.view.View
import android.widget.AdapterView
import androidx.recyclerview.widget.GridLayoutManager
import com.andr.common.http.callback.BaseCallback
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.adapter.CommonGridItemDecoration
import com.ellricky.baselib.adapter.cla.TeacherAddAdapter
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.entity.cla.TcAddEntity
import com.ellricky.baselib.entity.new.TeacherList
import com.ellricky.baselib.http.Api
import com.ellricky.baselib.http.callback.EListCallback
import com.ellricky.baselib.util.NewEBaseCallback
import com.ellricky.baselib.util.NewEListCallback
import kotlinx.android.synthetic.main.base_activity_person_add.*

class TeacherAddActivity : PersonAddActivity() {

    private lateinit var adapter: TeacherAddAdapter
    private var chooseEntity: TeacherList? = null

    override fun initUIView() {
        super.initUIView()
        mTvTitle.text = "添加教师"
        etSearch.hint = "搜索您要寻找的教师"
        initRv()
    }

    private fun initRv() {
        rvPerson.layoutManager = GridLayoutManager(this, 3)
        rvPerson.addItemDecoration(CommonGridItemDecoration(this, 3, 12))
        adapter = TeacherAddAdapter(this)
        adapter.setOnItemClickListener(this)
        rvPerson.adapter = adapter
    }

    override fun getUrlPath() = ""

    override fun getResponseCallback(): NewEBaseCallback {
        return object : NewEListCallback<TeacherList>(this) {
            override fun onSuccess(data: MutableList<TeacherList>?, msg: String?) {
                adapter.refresh(data ?: mutableListOf())
            }
        }
    }

    override fun label(): CharSequence? = "添加教师"

    override fun addPersonParam(paramMap: HashMap<String, String>) {
        paramMap["action"] = "gzaAddTeacher"
        paramMap["teacher_user_id"] = chooseEntity?.id.toString()
    }

    override fun queryPersonParam(paramMap: HashMap<String, String>) {
        paramMap["action"] = "gzaTeacherList"
        paramMap["school_id"] = LocalCacheUtil.getSchoolId()
    }

    override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
        adapter.choosePos = position
        adapter.notifyDataSetChanged()
        chooseEntity = adapter[position]
    }
}